/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package generalModel.impl;

import generalModel.CPU;
import generalModel.Data;
import generalModel.GeneralModelPackage;
import generalModel.SubTask;

import java.util.Collection;

import org.eclipse.emf.common.notify.Notification;

import org.eclipse.emf.common.util.EList;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.impl.EObjectImpl;

import org.eclipse.emf.ecore.util.EObjectResolvingEList;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Sub Task</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link generalModel.impl.SubTaskImpl#getDatas <em>Datas</em>}</li>
 *   <li>{@link generalModel.impl.SubTaskImpl#getCpu <em>Cpu</em>}</li>
 *   <li>{@link generalModel.impl.SubTaskImpl#getSubId <em>Sub Id</em>}</li>
 *   <li>{@link generalModel.impl.SubTaskImpl#getWcet <em>Wcet</em>}</li>
 *   <li>{@link generalModel.impl.SubTaskImpl#getPriority <em>Priority</em>}</li>
 *   <li>{@link generalModel.impl.SubTaskImpl#isAtomic <em>Atomic</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class SubTaskImpl extends EObjectImpl implements SubTask {
	/**
	 * The cached value of the '{@link #getDatas() <em>Datas</em>}' reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getDatas()
	 * @generated
	 * @ordered
	 */
	protected EList<Data> datas;

	/**
	 * The cached value of the '{@link #getCpu() <em>Cpu</em>}' reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getCpu()
	 * @generated
	 * @ordered
	 */
	protected CPU cpu;

	/**
	 * The default value of the '{@link #getSubId() <em>Sub Id</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getSubId()
	 * @generated
	 * @ordered
	 */
	protected static final String SUB_ID_EDEFAULT = null;

	/**
	 * The cached value of the '{@link #getSubId() <em>Sub Id</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getSubId()
	 * @generated
	 * @ordered
	 */
	protected String subId = SUB_ID_EDEFAULT;

	/**
	 * The default value of the '{@link #getWcet() <em>Wcet</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getWcet()
	 * @generated
	 * @ordered
	 */
	protected static final int WCET_EDEFAULT = 0;

	/**
	 * The cached value of the '{@link #getWcet() <em>Wcet</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getWcet()
	 * @generated
	 * @ordered
	 */
	protected int wcet = WCET_EDEFAULT;

	/**
	 * The default value of the '{@link #getPriority() <em>Priority</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getPriority()
	 * @generated
	 * @ordered
	 */
	protected static final int PRIORITY_EDEFAULT = 0;

	/**
	 * The cached value of the '{@link #getPriority() <em>Priority</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getPriority()
	 * @generated
	 * @ordered
	 */
	protected int priority = PRIORITY_EDEFAULT;

	/**
	 * The default value of the '{@link #isAtomic() <em>Atomic</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #isAtomic()
	 * @generated
	 * @ordered
	 */
	protected static final boolean ATOMIC_EDEFAULT = false;

	/**
	 * The cached value of the '{@link #isAtomic() <em>Atomic</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #isAtomic()
	 * @generated
	 * @ordered
	 */
	protected boolean atomic = ATOMIC_EDEFAULT;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected SubTaskImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return GeneralModelPackage.Literals.SUB_TASK;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<Data> getDatas() {
		if (datas == null) {
			datas = new EObjectResolvingEList<Data>(Data.class, this, GeneralModelPackage.SUB_TASK__DATAS);
		}
		return datas;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public CPU getCpu() {
		if (cpu != null && cpu.eIsProxy()) {
			InternalEObject oldCpu = (InternalEObject)cpu;
			cpu = (CPU)eResolveProxy(oldCpu);
			if (cpu != oldCpu) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, GeneralModelPackage.SUB_TASK__CPU, oldCpu, cpu));
			}
		}
		return cpu;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public CPU basicGetCpu() {
		return cpu;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setCpu(CPU newCpu) {
		CPU oldCpu = cpu;
		cpu = newCpu;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, GeneralModelPackage.SUB_TASK__CPU, oldCpu, cpu));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public String getSubId() {
		return subId;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setSubId(String newSubId) {
		String oldSubId = subId;
		subId = newSubId;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, GeneralModelPackage.SUB_TASK__SUB_ID, oldSubId, subId));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public int getWcet() {
		return wcet;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setWcet(int newWcet) {
		int oldWcet = wcet;
		wcet = newWcet;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, GeneralModelPackage.SUB_TASK__WCET, oldWcet, wcet));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public int getPriority() {
		return priority;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setPriority(int newPriority) {
		int oldPriority = priority;
		priority = newPriority;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, GeneralModelPackage.SUB_TASK__PRIORITY, oldPriority, priority));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public boolean isAtomic() {
		return atomic;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setAtomic(boolean newAtomic) {
		boolean oldAtomic = atomic;
		atomic = newAtomic;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, GeneralModelPackage.SUB_TASK__ATOMIC, oldAtomic, atomic));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case GeneralModelPackage.SUB_TASK__DATAS:
				return getDatas();
			case GeneralModelPackage.SUB_TASK__CPU:
				if (resolve) return getCpu();
				return basicGetCpu();
			case GeneralModelPackage.SUB_TASK__SUB_ID:
				return getSubId();
			case GeneralModelPackage.SUB_TASK__WCET:
				return new Integer(getWcet());
			case GeneralModelPackage.SUB_TASK__PRIORITY:
				return new Integer(getPriority());
			case GeneralModelPackage.SUB_TASK__ATOMIC:
				return isAtomic() ? Boolean.TRUE : Boolean.FALSE;
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case GeneralModelPackage.SUB_TASK__DATAS:
				getDatas().clear();
				getDatas().addAll((Collection<? extends Data>)newValue);
				return;
			case GeneralModelPackage.SUB_TASK__CPU:
				setCpu((CPU)newValue);
				return;
			case GeneralModelPackage.SUB_TASK__SUB_ID:
				setSubId((String)newValue);
				return;
			case GeneralModelPackage.SUB_TASK__WCET:
				setWcet(((Integer)newValue).intValue());
				return;
			case GeneralModelPackage.SUB_TASK__PRIORITY:
				setPriority(((Integer)newValue).intValue());
				return;
			case GeneralModelPackage.SUB_TASK__ATOMIC:
				setAtomic(((Boolean)newValue).booleanValue());
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case GeneralModelPackage.SUB_TASK__DATAS:
				getDatas().clear();
				return;
			case GeneralModelPackage.SUB_TASK__CPU:
				setCpu((CPU)null);
				return;
			case GeneralModelPackage.SUB_TASK__SUB_ID:
				setSubId(SUB_ID_EDEFAULT);
				return;
			case GeneralModelPackage.SUB_TASK__WCET:
				setWcet(WCET_EDEFAULT);
				return;
			case GeneralModelPackage.SUB_TASK__PRIORITY:
				setPriority(PRIORITY_EDEFAULT);
				return;
			case GeneralModelPackage.SUB_TASK__ATOMIC:
				setAtomic(ATOMIC_EDEFAULT);
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case GeneralModelPackage.SUB_TASK__DATAS:
				return datas != null && !datas.isEmpty();
			case GeneralModelPackage.SUB_TASK__CPU:
				return cpu != null;
			case GeneralModelPackage.SUB_TASK__SUB_ID:
				return SUB_ID_EDEFAULT == null ? subId != null : !SUB_ID_EDEFAULT.equals(subId);
			case GeneralModelPackage.SUB_TASK__WCET:
				return wcet != WCET_EDEFAULT;
			case GeneralModelPackage.SUB_TASK__PRIORITY:
				return priority != PRIORITY_EDEFAULT;
			case GeneralModelPackage.SUB_TASK__ATOMIC:
				return atomic != ATOMIC_EDEFAULT;
		}
		return super.eIsSet(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public String toString() {
		if (eIsProxy()) return super.toString();

		StringBuffer result = new StringBuffer(super.toString());
		result.append(" (subId: ");
		result.append(subId);
		result.append(", wcet: ");
		result.append(wcet);
		result.append(", priority: ");
		result.append(priority);
		result.append(", atomic: ");
		result.append(atomic);
		result.append(')');
		return result.toString();
	}

} //SubTaskImpl
